package com.nf.health.app.activity.home.adapter;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.activity.global.WebViewActivity;
import com.nf.health.app.activity.home.bean.MyHomeHospitalConsultationModel;
import com.nf.health.app.adapter.OnMyClickListener;
import com.nf.health.app.glide.GlideUtil;
import com.nf.health.app.utils.ActivityUtils;

import java.util.List;


/**
 * Created by Administrator on 2017/4/8 0008.
 */

public class HostipalConsulateAdapter extends BaseAdapter {

    private Context context;
    private List<MyHomeHospitalConsultationModel> list;
    public HostipalConsulateAdapter(Context context, List<MyHomeHospitalConsultationModel> list) {
        super();
        this.context = context;
        this.list = list;
    }
    @Override
    public int getCount() {
        if(list != null){
            return list.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView==null) {
            convertView = View.inflate(context,R.layout.item_hospital_consulate,null);
            holder = new ViewHolder();
            holder.iv_img = (ImageView) convertView.findViewById(R.id.iv_img);
            holder.tv_regimen_title = (TextView) convertView.findViewById(R.id.tv_regimen_title);
            holder.tv_regimen_content = (TextView) convertView.findViewById(R.id.tv_regimen_content);
            holder.ll_mufavorite = (LinearLayout) convertView.findViewById(R.id.ll_mufavorite);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final MyHomeHospitalConsultationModel myHomeHospitalConsultationModel = list.get(position);
        GlideUtil.loadNetImgC(context, holder.iv_img, myHomeHospitalConsultationModel.getHimg(), R.drawable.default_head);
        holder.tv_regimen_title.setText(myHomeHospitalConsultationModel.getTitle());
        holder.tv_regimen_content.setText(myHomeHospitalConsultationModel.getOutline());
        holder.ll_mufavorite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
//                WebModel webModel = new WebModel();
//                //先设置 右侧按钮是否可显示， 默认右侧都不显示，如果只加载URL，则需要 设置webModel.setUrl即可
//                if(myHomeHospitalConsultationModel.getFlag().equals("0")){//不显示收藏按钮
//                    webModel.setTAG_USER_SIGN_RIGHT1(0);
//                    webModel.setShowRightImg1(false);
//                }else  if(myHomeHospitalConsultationModel.getFlag().equals("1")) {//显示收藏按钮
//                    webModel.setTAG_USER_SIGN_RIGHT1(1);
//                    webModel.setShowRightImg1(true);
//                }
//                webModel.setShowRightImg2(true);
//                webModel.setTAG_USER_SIGN_RIGHT2(1);//显示分享按钮
//
//                webModel.setUrl(myHomeHospitalConsultationModel.getTourl());
//
//                webModel.setId(myHomeHospitalConsultationModel.getId() + "");
//                webModel.setObject(myHomeHospitalConsultationModel.getVtype());
//                bundle.putSerializable(WebModel.WEBFLAG_TAG, webModel);

                bundle.putString(WebViewActivity.KEY_TITLE,"资讯详情");
                bundle.putString(WebViewActivity.KEY_IMAGE,myHomeHospitalConsultationModel.getHimg());
                bundle.putString(WebViewActivity.KEY_URL, myHomeHospitalConsultationModel.getTourl());
                bundle.putBoolean(WebViewActivity.KEY_IS_SHARE, true);
                bundle.putString(WebViewActivity.KEY_SHARE_CONTENT, myHomeHospitalConsultationModel.getOutline());
                ActivityUtils.showActivity(context, WebViewActivity.class, bundle);

            }
        });
        return convertView;
    }
    private OnMyClickListener listener;
    public void setOnMyClickListener(OnMyClickListener listener){
        this.listener = listener;
    }

    public class ViewHolder{
        ImageView iv_img;
        TextView tv_regimen_title;
        TextView tv_regimen_content;
        LinearLayout ll_mufavorite;


    }
}
